package com.yueka.controller;

import com.yueka.pojo.Result;
import com.yueka.pojo.classroom.Classroom;
import com.yueka.service.ClassroomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/classroom")
@RestController
public class ClassroomController {
    @Autowired
    private ClassroomService classroomService;

    @GetMapping("/list")
    private Result list() {
        try {
            return Result.success(classroomService.list());
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }

    @PostMapping("/insert")
    private Result insert(@RequestBody Classroom classroom) {
        try {
            classroomService.insert(classroom);
            return Result.success();
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }

    @PostMapping("/update")
    private Result update(@RequestBody Classroom classroom) {
        try {
            classroomService.update(classroom);
            return Result.success();
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }

    @GetMapping("/delete")
    private Result delete(Integer id) {
        try {
            classroomService.delete(id);
            return Result.success();
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }

}
